#include "print_utils.h"

void
printrequest (char *log, int *log_len, char *s, int cnt, const char *name)
{
  int i;
  (*log_len) += sprintf (log + (*log_len), "[%s BEGIN]\n", name);
  for (i = 0; i < cnt; i++)
  {
    (*log_len) += sprintf (log + (*log_len), "%c", s[i]);
  }
  (*log_len) += sprintf (log + (*log_len), "\n");

  (*log_len) += sprintf (log + (*log_len), "[%s END]\n", name);
};

void
printheader (char *log, int *log_len, char *s, const char *name)
{
  char *s1 = s;
  int r = 0;
  (*log_len) += sprintf (log + (*log_len), "[%s BEGIN]\n", name);
  while ((*s1) && !(r && ((*s1) == '\r' || (*s1) == '\n')))
  {
    if ((*s1) == '\n')
      r = 1;
    else
      r = 0;
    (*log_len) += sprintf (log + (*log_len), "%c", *s1);
    s1++;
  }
  (*log_len) += sprintf (log + (*log_len), "\n");
  (*log_len) += sprintf (log + (*log_len), "[%s END]\n", name);

};

void
printlog (FILE * ptr, char *log, int *log_len)
{
  log[*log_len] = 0;
  fprintf (ptr, "%s\n", log);
}

void
mysetenv (char *log, int *log_len, const char *s1, char *s, int l)
{
  if ((*s))
  {
    setenv (s1, s, l);
    (*log_len) += sprintf (log + (*log_len), "_ENV[%s]=%s\n", s1, s);
  }
}


